//
//  ViewController.m
//  WilddogTestOBJ
//
//  Created by apple on 16/4/14.
//  Copyright © 2016年 SherrySorftware. All rights reserved.
//

#import "ViewController.h"
#import "CVWilddog.h"
@interface ViewController ()
{
    Wilddog *rootRef;
    __weak IBOutlet UITextField *QQ;
    __weak IBOutlet UITextField *PHONE;
    __weak IBOutlet UITextField *NICK;
    __weak IBOutlet UITextField *PWD;
    __weak IBOutlet UITextField *EM;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSDictionary *alanisawesome = @{
                                    @"full_name" : @"Alan Turing",
                                    @"date_of_birth": @"June 23, 1912"
                                    };
    NSDictionary *gracehop = @{
                               @"full_name" : @"Grace Hopper",
                               @"date_of_birth": @"December 9, 1906"
                               };
    
    NSDictionary *carvin = @{
                               @"full_name" : @"carvin Qiu",
                               @"date_of_birth": @"December 9, 2012"
                               };
    rootRef= [[Wilddog alloc] initWithUrl:@"https://wild-snake-11988.wilddogio.com"];

    Wilddog *usersRef = [rootRef childByAppendingPath: @"users"];
    NSDictionary *users = @{
                            @"alanisawesome": alanisawesome,
                            @"gracehop": gracehop,
                            @"carvin":carvin
                            };
//    [usersRef setValue:users withCompletionBlock:^(NSError *error, Wilddog *ref) {
//        
//    }];
    
}
- (IBAction)SIGNUP:(id)sender {
    Wilddog *person = [rootRef childByAppendingPath:@"person"];
    NSDictionary *dic = @{
                          @"userName":EM.text,
                          @"phone":PHONE.text,
                          @"pwd":PWD.text,
                          @"qq":QQ.text,
                          @"nickName":NICK.text
                          };
    NSDictionary *user = @{EM.text:dic};
//    [person updateChildValues:user withCompletionBlock:^(NSError *error, Wilddog *ref) {
//        NSLog(@"更新成功");
//    }];
    
    
    //创建user
    [rootRef createUser:EM.text password:PWD.text withValueCompletionBlock:^(NSError *error, NSDictionary *result) {
        NSLog(@"用户==%@",result);
    }];
}
- (IBAction)login:(id)sender {
    [rootRef authUser:EM.text password:PWD.text withCompletionBlock:^(NSError *error, WAuthData *authData) {
        NSLog(@"%@",authData);
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
